import java.util.List;

/**
 * @author dreamcatcher
 * @date 2022/5/4 11:00
 */
public class View {

    /**
     * 点击事件监听器
     */
    ClickListener clickListener;

    /**
     * 是否可以点击
     */
    private boolean clickAble;
    /**
     * 组件ID
     */
    private String id;
    /**
     * 组件内容
     */
    private String text;

    /**
     * 组件的高度
     */
    private String height;
    /**
     * 组件的宽度
     */
    private String weight;

    public boolean isClickAble() {
        return clickAble;
    }

    public void setClickAble(boolean clickAble) {
        this.clickAble = clickAble;
    }

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getText() {
        return text;
    }

    public void setText(String text) {
        this.text = text;
    }

    public String getHeight() {
        return height;
    }

    public void setHeight(String height) {
        this.height = height;
    }

    public String getWeight() {
        return weight;
    }

    public void setWeight(String weight) {
        this.weight = weight;
    }

    /**
     * 设置组件的点击事件，使用clickListner的回调方法
     */
    public void onClick() {
        if (clickAble && clickListener != null) {
            clickListener.onclick(this);
        } else if (!clickAble) {
            System.out.println(getId() + "不可点击");
        } else {
            System.out.println(getId() + "没有设置监听器");
        }
    }

    /**
     * 设置组件的点击事件监听器，如果设置了那么为可以点击，如果没设置那默认为不可以点击
     *
     * @param listener
     */
    void setOnClickListener(ClickListener listener) {
        clickAble = true;
        clickListener = listener;
    }

    /**
     * 点击事件监听器的接口
     */
    interface ClickListener {
        void onclick(View view);
    }

    @Override
    public String toString() {
        return  this.getClass().getName() + "{" +
                "clickAble=" + clickAble +
                ", id='" + id + '\'' +
                ", text='" + text + '\'' +
                ", height='" + height + '\'' +
                ", weight='" + weight + '\'' +
                '}';
    }
}
